from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.lancedb import LanceDb
from agno.models.openai import OpenAIChat, OpenAILike

# Set up knowledge base
from configs.basic_config import REMOTE_URL, ALI_DASHSCOPE_API_KEY, ALI_GENERATION_MODEL, AGENT_URL

knowledge = Knowledge(
    vector_db=LanceDb(
        table_name="zzc_documents",
        uri="tmp/lancedb"
    ),
)

# Add your content
knowledge.add_content(
    text_content="""
    Agno知识库

    知识库功能使AI智能体能够在运行时访问并搜索特定领域的信息，从而实现动态的小样本学习和智能检索增强生成能力。

    核心特性：
    - 自动内容分块
    - 向量相似度搜索
    - 多数据源支持
    - 智能检索机制
    """
)

# Create your agent
agent = Agent(
    model=OpenAIChat(id=ALI_GENERATION_MODEL, api_key=ALI_DASHSCOPE_API_KEY, base_url=AGENT_URL),
    # model=OpenAILike(),
    knowledge=knowledge,
    search_knowledge=True,
    instructions=["在回答问题之前总是先检索知识库"]
)

# Chat with your agent
if __name__ == "__main__":
    agent.print_response("What is Agno Knowledge?", stream=True)